package com.toman.widget.callback.http;

import android.app.Dialog;
import android.content.Context;
import android.support.annotation.Nullable;

import com.itheima.pulltorefreshlib.PullToRefreshScrollView;
import com.lzy.okhttputils.callback.StringCallback;
import com.lzy.okhttputils.request.BaseRequest;
import com.toman.Util.ProgressDialogUtils;
import com.toman.Util.StringUtils;
import com.toman.Util.ToastUtil;

import okhttp3.Call;
import okhttp3.Response;

/**
 * Created by 邹苏隆 on 2018/11/26.
 * description：
 */
public abstract class AddCallback extends StringCallback {
    private Dialog netDialog;
private Context context;
private String search;
    PullToRefreshScrollView mPullToRefreshScrollView;
    @Override
    public void onError(boolean isFromCache, Call call, @Nullable Response response, @Nullable Exception e) {
        super.onError(isFromCache, call, response, e);
        dismiss();
        ToastUtil.error(context, "请检查您的网络连接!");
    }



    private void dismiss() {
        if (netDialog!=null){
            netDialog.dismiss();}
    }

    public AddCallback(Context context) {
        this.context = context;
    }

    @Override

    public void onBefore(BaseRequest request) {
        super.onBefore(request);
            netDialog = ProgressDialogUtils.showProgressDialog(context, "网络请求中", "请稍后");
    }

    @Override
    public void onAfter(boolean isFromCache, @Nullable String s, Call call, @Nullable Response response, @Nullable Exception e) {
        super.onAfter(isFromCache, s, call, response, e);
        dismiss();

    }
}
